package mx.com.switz.peliculas.dao.impl;

import java.util.List;

import javax.sql.DataSource;

import mx.com.switz.peliculas.dao.UsuarioDao;


import mx.com.switz.peliculas.dto.Socio;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;

@Repository
public class UsuarioDaoImpl extends JdbcDaoSupport implements UsuarioDao {
	
	private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
	@Autowired
	public UsuarioDaoImpl(DataSource dataSource){
		setDataSource(dataSource);
		this.namedParameterJdbcTemplate= new NamedParameterJdbcTemplate(dataSource);
	}
	

	
	

	@Override
	public List<Socio> selectAll() {
		// TODO Auto-generated method stub
		return getJdbcTemplate().query("select * from socio",
				ParameterizedBeanPropertyRowMapper.newInstance(Socio.class));
	}
	
	
	@Override
	public List<Socio> selectUsuarioByNombre(Socio socio) {
	// TODO Auto-generated method stub
	String query = "SELECT * from socio where nombre= :nombre";
	SqlParameterSource namedParameters = new BeanPropertySqlParameterSource(socio);
	return namedParameterJdbcTemplate.query(query,
	namedParameters, ParameterizedBeanPropertyRowMapper.newInstance(Socio.class));
	
	}


}
